package com.yonyou.lxp.xutils3test.ui;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.yonyou.lxp.xutils3test.R;
import com.yonyou.lxp.xutils3test.adapter.BaseAdapter;
import com.yonyou.lxp.xutils3test.adapter.CommonAdapter;
import com.yonyou.lxp.xutils3test.adapter.RecyclerViewAdapter;
import com.yonyou.lxp.xutils3test.adapter.ViewHolder;

import org.lucasr.twowayview.TwoWayView;
import org.xutils.common.util.LogUtil;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;


/**
 * 驾照考试
 */
@ContentView(R.layout.activity_exam)
public class ExamActivity extends BaseTwoActivity {

    @ViewInject(R.id.rv)
    RecyclerView mRecyclerView;
    private CommonAdapter<String> adapter;
    private RecyclerViewAdapter adapter2;
    private List<String> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        init();
        getData();
        init2();

    }
    private void getData(){
        for (int i = 0; i < 50; i++) {
            list.add(i+"=====");
        }
    }

    /**
     * http://api2.juheapi.com/jztk/query?subject=1&model=c1&key=90c2a8b76b76f8b932546868d9833e9b&testType=rand
     */

    private void init2(){
        adapter2= new RecyclerViewAdapter<String>(mContext, list, 0, R.layout.item_img) {
            @Override
            public void convert(ViewHolder helper, String item, int position) {
                helper.setText(R.id.tv_testtv,item);
                helper.setImageResource(R.id.item_img,R.mipmap.ic_back);
            }
        };
        adapter2.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, long id, View view) {
                LogUtil.e(position+"=====");
            }
        });

        adapter2.setOnLoadingListener(new BaseAdapter.OnLoadingListener() {
            @Override
            public void onLoading() {
                LogUtil.e("onLoading");
            }
        });


        adapter2.setOnLoadingHeaderCallBack(new BaseAdapter.OnLoadingHeaderCallBack() {
            @Override
            public RecyclerView.ViewHolder onCreateHeaderHolder(ViewGroup parent) {
                TextView textView =new TextView(mContext);
                textView.setText("di");
                return new BaseAdapter.FooterViewHolder(textView);
            }

            @Override
            public void onBindHeaderHolder(RecyclerView.ViewHolder holder, int position) {

            }
        });

        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerView.setAdapter(adapter2);

        adapter2.notifyDataSetChanged();
    }
}
